package com.blue.code.db.bean;

import java.util.ArrayList;
import java.util.List;

import com.blue.code.db.src.TableColumn;
import com.blue.code.util.SqlTypeConvertor;
import com.blue.core.util.ReflectionUtil;

public class EntityColumn
{
	protected String name;
	protected String column;
	protected String field;
	protected String getter;
	protected String setter;
	protected String type;
	protected boolean nullable;
	protected int size;
	protected String def;
	protected String comment;

	public EntityColumn()
	{
	}

	public static EntityColumn toColumn(TableColumn tableColumn)
	{
		EntityColumn column = new EntityColumn();
		column.setName(tableColumn.getName());
		column.setColumn(tableColumn.getColumn());
		column.setField(ReflectionUtil.columnToField(column.column));
		column.setGetter(ReflectionUtil.fieldToGetter(column.field));
		column.setSetter(ReflectionUtil.fieldToSetter(column.field));
		column.setNullable(tableColumn.isNullable());
		column.setSize(tableColumn.getSize());
		column.setDef(tableColumn.getDef());
		column.setComment(tableColumn.getComment());
		column.setType(SqlTypeConvertor.sqlTypeToJava(tableColumn.getType()));
		return column;
	}

	public static List<EntityColumn> toColumn(List<TableColumn> list)
	{
		List<EntityColumn> columnList = new ArrayList<>();
		if (list == null || list.isEmpty())
			return columnList;

		for (TableColumn c : list)
		{
			columnList.add(toColumn(c));
		}
		return columnList;
	}

	public String getName()
	{
		return name;
	}

	public void setName(String name)
	{
		this.name = name;
	}

	public String getColumn()
	{
		return column;
	}

	public void setColumn(String column)
	{
		this.column = column;
	}

	public String getField()
	{
		return field;
	}

	public void setField(String field)
	{
		this.field = field;
	}

	public String getGetter()
	{
		return getter;
	}

	public void setGetter(String getter)
	{
		this.getter = getter;
	}

	public String getSetter()
	{
		return setter;
	}

	public void setSetter(String setter)
	{
		this.setter = setter;
	}

	public String getType()
	{
		return type;
	}

	public void setType(String type)
	{
		this.type = type;
	}

	public boolean isNullable()
	{
		return nullable;
	}

	public void setNullable(boolean nullable)
	{
		this.nullable = nullable;
	}

	public int getSize()
	{
		return size;
	}

	public void setSize(int size)
	{
		this.size = size;
	}

	public String getDef()
	{
		return def;
	}

	public void setDef(String def)
	{
		this.def = def;
	}

	public String getComment()
	{
		return comment;
	}

	public void setComment(String comment)
	{
		this.comment = comment;
	}

}
